package com.lengyue.imakiba.manage;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.lengyue.imakiba.data.Type;
import com.lengyue.imakiba.logic.TypeLogic;

public class TypeManage extends Controller {
	public void index()
	{
		render("/WEB-INF/freeMarkerTemplete/type_edit.ftl");
	}
	public void getType()
	{
		List<Type> type = TypeLogic.getAllTypesAndSort();
		renderJson(type);
	}
	public void saveType()
	{
		if(getPara("id")==null||getPara("id")=="")
		{
			addType();
		}else
		{
			updateType();
		}
	}
	public void addType()
	{
		Type type = new Type().set("type_code", getPara("type_code")).set("sort_no", getPara("sort_no"));
		type.save();
		renderJson(type);
	}
	public void updateType()
	{
		Type type = Type.dao.set("type_code", getPara("type_code")).set("sort_no", getPara("sort_no"));
		type.update();
		renderJson(type);
	}
	public void deleteType()
	{
		TypeLogic.deleteTypeById(Integer.parseInt(getPara("id")));
		renderNull();
	}
}
